package com.itheima.controller;

import com.itheima.R;
import com.itheima.dto.PmsProductParam;
import com.itheima.dto.PmsPruductQueryParam;
import com.itheima.service.PmsProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author chensen
 * @create 2022/10/14/18:58
 */
@RestController
@RequestMapping("product")
public class PmsProductController {
    @Autowired
    private PmsProductService pmsProductService;


    /**
     * 创建商品
     * @param productParam
     * @return
     */
    @PostMapping("create")
    public R create(@RequestBody PmsProductParam productParam) {
        return pmsProductService.create(productParam);
    }

    /**
     *查询商品
     * @param productQueryParam
     * @param pageSize
     * @param pageNum
     * @return
     */
    @GetMapping("list")
    public R getList(PmsPruductQueryParam productQueryParam,
                                @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                                @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum){
        return pmsProductService.listByCondition(productQueryParam,pageNum,pageSize);
    }

    /**
     * 根据商品名称或货号模糊查询
     * @param keyword
     * @return
     */
    @GetMapping("simpleList")
    public R simpleList(String keyword){
        return pmsProductService.list(keyword);
    }

    /**
     * 批量修改删除状态
     * @param ids
     * @param deleteStatus
     * @return
     */
    @PostMapping("update/deleteStatus")
    public R delete(@RequestParam("ids") List<Long> ids,
                               @RequestParam("deleteStatus") Integer deleteStatus){
        return pmsProductService.updateDeleteStatus(ids,deleteStatus);
    }

    /**
     * 批量设为新品
     * @param ids
     * @param newStatus
     * @return
     */
    @PostMapping("update/newStatus")
    public R updateStatus(@RequestParam("ids") List<Long> ids,
                                     @RequestParam("newStatus") Integer newStatus){
        return pmsProductService.updateNewStatus(ids,newStatus);
    }

    /**
     * 批量上下架商品
     * @param ids
     * @param publishStatus
     * @return
     */
    @PostMapping("update/publishStatus")
    public R updatePublishStatus(@RequestParam("ids") List<Long> ids,
                                            @RequestParam("publishStatus") Integer publishStatus){
        return pmsProductService.updatePublishStatus(ids,publishStatus);
    }

    /**
     * 批量推荐商品
     * @param ids
     * @param recommendStatus
     * @return
     */
    @PostMapping("update/recommendStatus")
    public R updateRecommendStatus(@RequestParam("ids") List<Long> ids,
                                              @RequestParam("recommendStatus") Integer recommendStatus){
        return pmsProductService.updateRecommendStatus(ids,recommendStatus);
    }

    /**
     * 批量修改审核状态
     * @param ids
     * @param verifyStatus
     * @param detail
     * @return
     */
    @PostMapping("update/verifyStatus")
    public R updateVerifyStatus(@RequestParam("ids") List<Long> ids,
                                           @RequestParam("verifyStatus") Integer verifyStatus,
                                           @RequestParam("detail") String detail){
        return pmsProductService.updateVerifyStatus(ids,verifyStatus,detail);
    }

    /**
     * 更新商品
     * @param id
     * @param productParam
     * @return
     */
    @PostMapping("update/{id}")
    public R update(@PathVariable Long id, @RequestBody PmsProductParam productParam){
        return pmsProductService.update(id,productParam);
    }

    /**
     * 根据商品id获取商品编辑信息
     * @param id
     * @return
     */
    @GetMapping("updateInfo/{id}")
    public R updateInfo(@PathVariable Long id){
        return pmsProductService.updateInfo(id);
    }
}
